import numpy as np
import matplotlib.pyplot as plt
import os

# define data directory
fname = 'exfig3e.npz'

# load npz file
data = np.load(fname, allow_pickle=True)
print(data.files)
B_up = data['B_up']
B_down = data['B_down']
Rxy_up = data['Rxy_up']
Rxy_down = data['Rxy_down']
B_lin = data['B_lin']
Rxy_asym = data['Rxy_asym']
Temperature = data['Temperature']
indices = data['indices']


# plot raw data
fig, ax = plt.subplots()
fig.suptitle('exfig3e raw data')
for i in indices:
    ax.plot(B_up[:,i], -Rxy_up[:, i], label='T = ' + str(Temperature[i]) + ' K')
    ax.plot(B_down[:,i], -Rxy_down[:, i], label='T = ' + str(Temperature[i]) + ' K')
ax.set_xlabel('$B$ (T)')
ax.set_ylabel('$R_{yx}$ raw')
ax.legend()
plt.show()

# plot processed data
fig, ax = plt.subplots()
fig.suptitle('exfig3e antisymmetrized data')
for i in indices:
    ax.plot(B_lin, -Rxy_asym[:, i], label='T = ' + str(Temperature[i]) + ' K')
    ax.plot(B_lin, Rxy_asym[::-1, i], label='T = ' + str(Temperature[i]) + ' K')
ax.set_xlabel('$B$ (T)')
ax.set_ylabel('$R_{yx}$ antisymmetrized')
ax.legend()
plt.show()